    /* global FormData visitUrl*/
    /* global getCookie */
    /* global template */
   
    var appearanceList = [];
    var imgList = {};
    var list = [];
    var imgPath = '';
    (function ($) {
 
         //一级分类
         $.ajax({
            type:'POST',
            url:"/antique/api/sysDict/query_list",
            data: { type:"firstcategory","token":getCookie('token') },
            dataType:"json",
            success:function(result){ 
                if (result.code == 0) {
                    if (result.data && result.data.list && result.data.list.length > 0) {
                        var list = result.data.list;
                        for (var i = 0; i < list.length;i++) { 
                            $("#firstCategory").append("<option value='" + list[i].id + "'>" + list[i].label + "</option>");
                        }
                        
                    }
                }
            }
                   
        });
        //品相
        $.ajax({
            type:'POST',
            url:"/antique/api/sysDict/query_list",
            data: { type:"appearance","token":getCookie('token') },
            dataType:"json",
            success:function(res){ 
                if (res.code == 0){
                    if (res.code == 0){
                        var list = res.data.list;
                        for (var i in list){
                            var onetype = {};
                            onetype.value = list[i].id;
                            onetype.title = list[i].label;
                            appearanceList.push(onetype);
                        }
                        $("#appearance").select({
                            title: "藏品品相",
                            items: appearanceList,
                            onChange: function(res) {
                              },
                          });


                    }
                     
                }
                
            }
        });


       
    })(jQuery);

    $("#firstCategory").change(function(){
        var value = $("#firstCategory").val();
        $("#secondCategory").empty();
        $.ajax({
            type:'POST',
            url:"/antique/api/sysDict/query_list",
            data: { type:"secondcategory","token":getCookie('token'),parentId:value },
            dataType:"json",
            success:function(result){
                if (result.code == 0) {
                    if (result.data && result.data.list && result.data.list.length > 0) {
                        var list = result.data.list;
                        for (var i = 0; i < list.length;i++) { 
                            $("#secondCategory").append("<option value='" + list[i].id + "'>" + list[i].label + "</option>");
                        }
                        
                    }
                }
                
            }
        }); 
    });
    function delImg(img){
        var allImg = $("#showImages").val();
        if (img && allImg){
            var imgPath2 = '';
            var imgs = allImg.split(',');
             list = [];
             imgList = {};
            for (var i = 0; i < imgs.length; i++) {
                if (imgs[i] != img) {
                    var a = {};
                    a.path = imgs[i] ;
                    list.push(a);
                    imgPath2 = imgPath2 + imgs[i] +  ","  ;
                }
            }

            imgPath = imgPath2;
            imgList.list = list;
            imgList.imgPath = imgPath2.substring(0, imgPath2.length - 1);
            var html = template ('pho', imgList);
            document.getElementById('uploaderFiles').innerHTML = html;
        }
        
    }
    $("#uploaderInput").on("change", function(e) {
        var file = e.target.files[0];
        /* global handlePic*/
        handlePic(file,2160,function(res){
            if (res.code == 0){
                var a = {};
                a.path = res.data.path;
                imgPath = imgPath + res.data.path + "," ;
                list.push(a);
                imgList.list = list;
                imgList.imgPath = imgPath.substring(0, imgPath.length - 1);
                var html = template ('pho', imgList);
                document.getElementById('uploaderFiles').innerHTML = html;
            } else {
                $.toast(res.message, "cancel");
            }
        });
        
    });
    $("#detailsDesc").keyup(function() {
        var value = $.trim(this.value);
        var descLength = $.trim(this.value).length;
        if (descLength <= 200) { 
            $("#descNumber").html(descLength);
        } else {
            $("#detailsDesc").val(value.substring(0,200));
        }
    });

    function puilcPro(){
        
        var productName = $("#productName").val();
        var productPrice = $("#productPrice").val();
        var sizeDesc = $("#sizeDesc").val();
        var firstCategory = $("#firstCategory").children('option:selected').val();
        var secondCategory = $("#secondCategory").children('option:selected').val();
        var appearance = $("#appearance").data('values');
        var detailsDesc = $("#detailsDesc").val();
        var showImages = $("#showImages").val();
        if (productName == ''){
            $.toast("名称不能为空", "cancel");
            return;
        }
        if (productPrice == ''){
            $.toast("价格不能为空", "cancel");
            return;
        }
        if (sizeDesc == ''){
            $.toast("尺寸不能为空", "cancel");
            return;
        }
        if (firstCategory == ''){
            $.toast("分类不能为空", "cancel");
            return;
        }
        if (secondCategory == '' || typeof secondCategory == 'undefined'){
            $.toast("分类不能为空", "cancel");
            return;
        }
        if (appearance == ''){
            $.toast("品相不能为空", "cancel");
            return;
        }
        if (detailsDesc == ''){
            $.toast("描述不能为空", "cancel");
            return;
        }
        if (typeof showImages == 'undefined' || showImages == ''){
            $.toast("请上传图片", "cancel");
            return;
        }

        var params = {};
        params.productName = productName;
        params.productPrice = productPrice;
        params.sizeDesc = sizeDesc;
        params.firstCategory = firstCategory;
        params.secondCategory = secondCategory;
        params.appearance = appearance;
        params.detailsDesc = detailsDesc;
        params.showImages = showImages;
        params.token = getCookie('token');

        addPro(params);
          

    } 

    function addPro(params){
        $.ajax({
            type:'POST',
            url:"/antique/api/mallConsignOrder/consign_add",
            data: params,
            dataType:"json",
            success:function(res){
                if (res.code == 0){
                    /* global isMiniProgram wx */
                    $.toast("成功");
                    if ( isMiniProgram () ) {//小程序
                        wx.miniProgram.redirectTo({
                            url: "/pages/transport_collection"
                        });
                    } else {
                        visitUrl(document.referrer,true);
                    }
                 } else {
                    $.toast(res.message, "cancel");
                }
                
            }
        });
    }
   


